<?php
class Ext_Object
{
	protected $_config;
	protected $_name;
	protected $_isExtended = false;
	
	public function __construct(){
		$this->_loadConfig();
	}
	/**
	 * Compile object as extended component
	 * @param boolean $flag
	 */
	public function extendedCompomemt($flag){
		$this->_isExtended = $flag;
	}
	
	public function isExtendedCompomemt(){
		return $this->_isExtended;
	}
	/**
	 * Get Object class
	 * @return string
	 */
	public function getClass()
	{
		return str_replace('Ext_Object_' , '' , get_called_class());
	}
	
	protected function _loadConfig()
	{	
		$this->_config = new Ext_Config(Ext::getPropertyClass(str_replace('Ext_Object_', '', $this->getClass())));
	}
	/**
	 * Set object name
	 * @param string $name
	 */
	public function setName($name){
		$this->_name = $name;
	}
	/**
	 * Get object name
	 * @return string
	 */
	public function getName(){
		return $this->_name;
	}
	
	public function __get($name)
	{
		return $this->_config->$name;
	}
	
	public function __set($name , $value)
	{
		$this->_config->$name = $value;
	}
	/**
	 * Get object Config
	 * @return Ext_Config
	 */
	public function getConfig()
	{
		return $this->_config;
	}
	/**
	 * Check if properti is valid
	 * @param string $name
	 * @return bolean
	 */
	public function isValidProperty($name)
	{
		return $this->_config->isValidProperty($name);
	}
	
	public function getDefineJs($namespace = false){
		
		if($namespace)
			$name = $namespace.'.'.$this->getName();
		else 
			$name = $this->getName();
			
		return '
		Ext.define("'.$name.'",{
				extend:"'.$this->_config->getExtends().'",
				constructor: function(config) {	
				config = Ext.apply(
			        '.$this->_config->__toString().'
			    , config);		
				this.callParent(arguments);
			}
		});
	   ';
	}
}